package openadmin;

import java.security.NoSuchAlgorithmException;
import java.util.Date;

import openadmin.dao.exception.DataException;
import openadmin.dao.operation.DaoJpaHibernate;
import openadmin.dao.operation.DaoOperationFacade;
import openadmin.dao.operation.LogDao;
import openadmin.dao.operation.LogOperationFacade;
import openadmin.model.control.User;
import openadmin.model.person.Person;
import openadmin.util.SerialClone;
import openadmin.util.configuration.TypeLanguages;

public class Test {

	
	public static void main(String[] args) throws NoSuchAlgorithmException, DataException{
		
		
		Date data = new Date();		
		
		String xx = "l'emili||l'Alex";		
		
		User usu = new User();		
		usu.setDescription("root");
		usu.setPassword("RootPassword");
		usu.setFullName("Alfred Oliver");
		usu.setIdentifier("234111");
		usu.setDateBegin(data);		
		usu.setLanguage(TypeLanguages.ca.toString());
		usu.setActive(true);
		
		Person per = new Person();
		
		per.setDescription("%222222%");
		
		DaoOperationFacade clientLog = new DaoJpaHibernate(usu, "log_post", null);				
		LogOperationFacade log = new LogDao(clientLog, "persona");
		DaoOperationFacade client = new DaoJpaHibernate(usu, "ayto_post", log);		
		
			
		Person per2 = (Person)client.findObjectDescription(per);
		Person per1 = SerialClone.clone(per2);
		client.begin();
		
		if (per2 != null){
			per2.setNif("222222");
			per2.setName("Maite");
			per2.setPartsurname1("del");
			per2.setSurname1("Oliver");
			per2.setSurname2("fort");
			per2.setNote("Prova");
			per2.setHistoricLog(true);
			log.detailLog(per1, per2);
			client.updateObject(per1, per2);
		}
		
		
		//client.persistObject(per);
		
		
		
		client.commit();
		
		
		client.finalize();
		log.finalizeLog();

	}

}
